///////////////////////////////////////////////////////////////////////////////
// Project: Hoyo Client Game
//
// hy_random.h
// Created: 2013-7-15
// Author: Like Cheng
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "hy_includes.h"

#define MAX_RANDOMED_ENTITIES		20
class hy_random : public hy_object
{
public:
	struct hy_prob_entity
	{
		void			*m_entity;
		int				m_prob;
		int				m_num;
		std::string		m_string;
	};

	hy_random();
	virtual ~hy_random();

	static hy_random*			instance();
	static void					purge_instance();
public:

	void						set_seed( int seed ) { m_seed = seed; srand(seed); }
	void						set_seed(){ srand((long)time(NULL)); }

	// Random positive integer
	int							next_int() { return rand(); }
	int							next_int( int mod );
	int							next_int( int start, int end ); // [start, end)

	// Random sign
	int							next_sign();

	// Percentage
	bool						pass( int perc );
	bool						passf( float perc );
	bool						passf2( float perc );
	int							pass_int( int perc, int start, int end, int nopassint = 0 );
	int							pass_float( float perc, int start, int end, int nopassint = 0 );
	int_vec						random_in_int_vec( int_vec& iv, int num = 1 );

	// Aggregation
	//PackedIntArray				getArrayBySize( PackedIntArray& array, int size );

	//void						clearProbEntityList();
	//void						addProbEntity( void* entity, int prob );
	//void						removeProbEntity( void* entity );
	//void*						getEntity();

	int							m_seed;

	hy_prob_entity				m_entities[MAX_RANDOMED_ENTITIES];
	int							m_num_entities;
};